package com.jn.exam.oss.config;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author 江南大学1033190417
 * @date 2022/1/31 17:09
 */
@Configuration
@Slf4j
@RefreshScope
public class OssConfig {

    //读取配置文件中的内容
    @Value("${aliyun.oss.file.endpoint}")
    private String endpoint;

    @Value("${aliyun.oss.file.keyid}")
    private String accessKeyId;

    @Value("${aliyun.oss.file.keysecret}")
    private String accessKeySecret;

    @Value("${aliyun.oss.file.bucketname}")
    private String bucketName;


    @Bean
    public OSS getOssClient(){
       OSS oss= new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
       log.info("创建OSS实例：{}",oss);
       return oss;
    }

}
